import app from '@/app'
import type { ToastMessageOptions } from 'primevue/toast'
import { useToast } from 'primevue/usetoast'
import { isString } from 'radash'

const getToast = () => app.config.globalProperties.$toast

const baseOption: Partial<ToastMessageOptions> = {
    severity: 'info',
    closable: true,
    life: 2000
}
export const Toast = (messageOption: string | ToastMessageOptions) => {
    const toast = useToast()
    if (isString(messageOption)) {
        toast.add({
            ...baseOption,
            summary: messageOption
        })
    } else {
        // console.log(getToast())
        toast.add({
            ...baseOption,
            ...messageOption
        })
    }
}
